<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------

namespace app\common\logic;

use \tpfcore\Core;
use think\Validate;
use think\facade\Request;
use tpfcore\web\Curl;

class ApiBase
{
	public function api_init($data=[]){
		$request = Request::instance();
		$config = config("config.api");
		$timestamp = $request->header("Timestamp");	
		$access_token = $request->header("Access-Token");		// 接口访问令牌  

		// 开户验证后才进行验证
		if($config && $config['validate'] == 1){
			// 验证IP
			if(!empty($config['ip_authorize']) && !in_array($request->ip(), explode("\n", $config['ip_authorize']))){
				return [100520,'此IP不在白名单中'];
			}
			if(empty($access_token) || empty($timestamp)){
				return [100520,"缺少必要参数"];
			}
			// 时间相差1分钟就不行
			if(time()-$timestamp > 60){
				return [400506,"你的时钟不对"];
			}
		}else{
			return [0,'success'];
		}
    }
}